package blueBridge;

import java.util.Arrays;
import java.util.Scanner;

/*

5
12349
54321



    1       2       3       4       9
    5       4       3       2       1
    0       1       2       3       4
0   4+7     2+5     5       2+2+1   8       i不进/退位
1   14+7    12+5    10+5    8+2-1   2       i进位
2   6+7     8+5     10+5    12+2+1  18      i退位


5
12341
54329


5
99995
00000


5
99905
00000

5
81450
58905


 */

public class Main3545_Two {
    char[] originNum;
    char[] targetNum;

    private Main3545_Two(char[] originNum, char[] targetNum) {
        super();
        this.originNum = originNum;
        this.targetNum = targetNum;
    }

    public int getMinOperateNum() {
        int n = originNum.length;
        int[][] dp = new int[3][n];
        // 初始化个位的dp，这位不用考虑进位和借位
        int deficit = targetNum[n-1] - originNum[n-1];
        // 不进位/借位
        dp[0][n-1] = Math.abs(deficit);
        // 进位
        dp[1][n-1] = 10 + deficit;
        // 借位
        dp[2][n-1] = 10 - deficit;
        System.out.println(dp[0][n-1] + ", " + dp[1][n-1] + ", " + dp[2][n-1]);
        for (int i = n-2; i >= 0; i--) {
            System.out.println(Math.abs(targetNum[i] - originNum[i] - 1) + dp[1][i+1]);
            dp[0][i] = Math.min(Math.min(Math.abs(targetNum[i] - originNum[i]) + dp[0][i+1], Math.abs(targetNum[i] - originNum[i] - 1) + dp[1][i+1]), Math.abs(targetNum[i] - originNum[i] + 1) + dp[2][i+1]);
            dp[1][i] = Math.min(Math.min(10 + targetNum[i] - originNum[i] + dp[0][i+1], 10 + targetNum[i] - originNum[i] - 1 + dp[1][i+1]), 10 + targetNum[i] - originNum[i] + 1 + dp[2][i+1]);
            dp[2][i] = Math.min(Math.min(10 - targetNum[i] + originNum[i] + dp[0][i+1], 10 - targetNum[i] + originNum[i] + 1 + dp[1][i+1]), 10 - targetNum[i] + originNum[i] - 1 + dp[2][i+1]);
            System.out.println(dp[0][i] + ", " + dp[1][i] + ", " + dp[2][i]);
            
        }
        return Math.min(Math.min(dp[0][0], dp[1][0]), dp[2][0]);
    }
    
    


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        char[] originNum = scan.next().toCharArray();
        char[] targetNum = scan.next().toCharArray();
        Main3545_Two main = new Main3545_Two(originNum, targetNum);
        System.out.println(main.getMinOperateNum());
    }

}
